package com.qst.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.Service.AdminOrderService;
import com.qst.Vo.AdminOrderVo;
import com.qst.pojo.Admin;
import com.qst.pojo.Order;
import com.qst.pojo.Room;
import org.aspectj.weaver.ast.Or;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @packageName:com.qst.controller
 * @className:AdminOrderController
 * @Description:
 * @author:zhangyu
 * @date 2021/6/20 22:26
 **/

@Controller
public class AdminOrderController {

    @Resource
    AdminOrderService adminOrderService;


    @RequestMapping(value = "/adminallorder")
    @ResponseBody
    public Map<String,Object> adminallorder(AdminOrderVo adminOrderVo){
        PageHelper.startPage(adminOrderVo.getPage(),adminOrderVo.getLimit());
        List<Order> orders = adminOrderService.adminAllorder(adminOrderVo);

        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo<Order> pageInfo = new PageInfo<Order>(orders);
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        System.out.println(map);
        return map;
    }

    @RequestMapping(value = "/addadminorder")
    @ResponseBody
    public Map<String,Object> addadminorder(Order order){
        Map<String,Object> map = new HashMap<String, Object>();
        if(adminOrderService.addadminorder(order)>0){
            map.put("success",true);
            map.put("message","添加成功");
        }else{
            map.put("success",false);
            map.put("message","添加失败");
        }
        return map;


    }
    @RequestMapping(value = "/updateadminorder")
    @ResponseBody
    public Map<String,Object> updateadminorder(Order order){
        Map<String,Object> map = new HashMap<String, Object>();
        if(adminOrderService.updateadminorder(order)>0){
            map.put("success",true);
            map.put("message","修改成功");
        }else{
            map.put("success",false);
            map.put("message","修改失败");
        }
        return map;


    }
    @RequestMapping(value = "/deleteadminorder")
    @ResponseBody
    public Map<String,Object> deleteadminorder(int id) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (adminOrderService.deleteadminorder(id) > 0) {
            map.put("success", true);
            map.put("message", "删除成功");
        } else {
            map.put("success", false);
            map.put("message", "删除失败");
        }
        return map;
    }



}
